home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 21
/
CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso
/
CUCD
/
Programming
/
PPCSmallTalk
/
docs
/
manbody
< prev
next >
Wrap
Text File
|
1986-10-19
|
28KB
|
1,350 lines
AAAA LLLLiiiittttttttlllleeee SSSSmmmmaaaallllllllttttaaaallllkkkk UUUUsssseeeerrrr MMMMaaaannnnuuuuaaaallll
Timothy A. Budd
_1. _I_n_t_r_o_d_u_c_t_i_o_n
This manual is intended as an aid in using the Little
Smalltalk system. It is not intended to be used as an
introduction to the Smalltalk language. Little Smalltalk is
largely (with exceptions listed in a later section) a subset
of the Smalltalk-80* language described in [.Smalltalk
blue.]. A complete description of the classes included in
the Little Smalltalk system and the messages they accept is
given in Appendix 1.
_2. _R_u_n_n_i_n_g _t_h_e _s_y_s_t_e_m
The Little Smalltalk system is invoked by typing the
command sssstttt. The system is interactive - that is, the user
types an expression at the keyboard and the system responds
by evaluating the expression and typing the result. For
example, typing the expression 3333 ++++ 4444 results in the value 7777
being displayed on the output. Execution is terminated by
typing control-D. A sample execution session is shown in
Figure 1.
% st
Little Smalltalk
3 + 4
7
^D
%
FFFFiiiigggguuuurrrreeee 1111:::: A Sample Little Smalltalk Session
Instance variables for the command level can be created
by assigning a value to a new variable name. Thereafter
that variable can be used at the command level, although it
is not known within the scope of any method. The variable
_________________________
* Smalltalk-80 is a trademark of the Xerox Corporation.
September 19, 1986
- 2 -
``last'' always contains the value returned by the last
expression typed. Figure 2 shows the creation of a vari-
able. Note that the assignment arrow is formed as a two
character sequence.
newvar <- 2 / 3
newvar
0.666667
2 raisedTo: newvar + (4 / 3)
4
last
4
FFFFiiiigggguuuurrrreeee 2222:::: Creating Variables
The default behavior is for the value of expressions,
with the exception of assignments, to be typed automatically
as they are evaluated. This behavior can be modified either
by using the -d flag (see Appendix 2), or by passing a mes-
sage to the pseudo variable ssssmmmmaaaallllllllttttaaaallllkkkk (see Appendix 1).
Class descriptions must be read in from files, they
cannot be entered interactively. Class descriptions are
entered using a system directive. For example, to include a
class description contained in a file named nnnneeeewwwwccccllllaaaassssssss....sssstttt, the
following system directive should be issued:
)i newclass.st
A list of files containing class descriptions can also be
given as arguments to the st command. The command
%st file1 ... filen
is equivalent to the sequence
%st
Little Smalltalk
)i file1
...
)i filen
A table of system directives is given in Figure 3.
Note that the )e system directive invokes an editor on
a file containing class descriptions, and then automatically
includes the file when the editor is exited. Classes also
respond to the message eeeeddddiiiitttt, which will have the same effect
as the )e directive applied to the file containing the class
description. Thus the typical debug/edit/debug cycle
September 19, 1986
- 3 -
_____________________________________________________________
)e filename
Edit the named file. The Little Smalltalk
system will suspend, leaving the user in an
editor for making changes to the named file.
Upon leaving the editor the named file will
automatically be included, as if the )i
directive had been typed.
)g filename
Search for an entry in the system library
area matching the filename. If found, the
class descriptions in the library entry are
included. This command is useful for
including commonly used classes that are not
part of the standard prelude, such as classes
for statistics applications or graphics.
)i filename
Include the named file. The file must
contain one or more class descriptions. The
class descriptions are parsed, and if
syntactically legal new instances of class
CCCCllllaaaassssssss are added to the Smalltalk system.
)l filename
Load a previously saved environment from the
named file. The current values of all
variables are overridden. The file must have
been created using the )s directive (below).
)r filename
Read the named file. The file must contain
Smalltalk statements, as would be typed at
the keyboard. The effect is just as if the
lines of the file had been typed at the
keyboard. The file cannot contain class
descriptions.
)s filename
Save the current state in the named file.
The values of all variables are saved, and
can later be reloaded using the )l directive
(above).
)!string
Execute the remainder of the line following
the exclamation point as a Unix* command.
Nothing is done with the output of the
command, nor is the returning status of the
command recorded.
_____________________________________________________________
||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||||||||||||||||||
FFFFiiiigggguuuurrrreeee 3333:::: System Directives
September 19, 1986
- 4 -
involves repeated uses of the )e directive or the eeeeddddiiiitttt mes-
sage until a desired outcome is achieved. The editor
invoked by the )e directive can be changed by setting the
EDITOR variable in the users environment.
_3. _D_i_f_f_e_r_e_n_c_e_s _b_e_t_w_e_e_n _L_i_t_t_l_e _S_m_a_l_l_t_a_l_k _a_n_d _t_h_e _S_m_a_l_l_t_a_l_k-
_8_0 _s_y_s_t_e_m
This section describes the differences between the
language accepted by the Little Smalltalk system and the
language described in [.Smalltalk blue.]. The principal
reasons for these changes are as follows:
size Classes which are largely unnecessary, or which could
be easily simulated by other classes (e.g. Associa-
tion, SortedCollection) have been eliminated in the
interest of keeping the size of the standard library
as small as possible. Similarly, indexed instance
variables are not supported, since to do so would
increase the size of every object in the system, and
they can be easily simulated in those classes in which
they are important (see below).
portability
Classes which depend upon particular hardware (e.g.
BitBlt) are not included as part of the Little
Smalltalk system. The basic system assumes nothing
more than ascii terminals.
representation
The need for a textual representation for class
descriptions required some small additions to the syn-
tax for class methods (see Appendix 3). Similarly,
the fact that classes and subclasses can be separately
parsed, in either order, forced some changes in the
scoping rules for instance variables.
The following sections describe these changes in more
detail.
_3._1. _N_o _B_r_o_w_s_e_r
The Smalltalk-80 Programming Environment described in
[.Smalltalk orange.] is not included as part of the Little
Smalltalk system. The Little Smalltalk system is designed
to be little, easily portable, and to rely on nothing more
than basic terminal capabilities.
_3._2. _I_n_t_e_r_n_a_l _R_e_p_r_e_s_e_n_t_a_t_i_o_n _D_i_f_f_e_r_e_n_t
The internal representations of objects, including
processes, interpreters, and bytecodes, is entirely dif-
ferent in the Little Smalltalk system from the Smalltalk-80
system described in [.Smalltalk blue.].
_________________________
* Unix is a trademark of Bell Laboratories.
September 19, 1986
- 5 -
_3._3. _F_e_w_e_r _C_l_a_s_s_e_s
Many of the classes described in [.Smalltalk blue.] are
not included as part of the Little Smalltalk basic system.
Some of these are not necessary because of the decision not
to include the editor, browser, and so on as part of the
basic system. Others are omitted in the interest of keeping
the standard library of classes small. A complete list of
included classes for the Little Smalltalk system is given in
Appendix 1.
_3._4. _N_o _C_l_a_s_s _P_r_o_t_o_c_o_l
Protocol for all classes is defined as part of class
CCCCllllaaaassssssss. It is not possible to redefine class protocol as
part of a class description, only instance protocol. The
notion of metaclasses is not supported.
_3._5. _C_a_s_c_a_d_e_s _D_i_f_f_e_r_e_n_t
The semantics of cascades has been simplified and gen-
eralized. The result of a cascaded expression is always the
result of the expression to the left of the first semicolon,
which is also the receiver for each subsequent continuation.
Continuations can include multiple messages. A rather non-
sensical, but illustrative, example is the following:
2 + 3 ; - 7 + 3 ; * 4
The result of this expression is 5 (the value yielded by 2 +
3). 5 is also the receiver for the message - 7, and that
result (-2) is in turn the receiver for the message + 3.
This last result is thrown away. 5 is then again used as
the receiver for the message * 4, the result of which is
also thrown away.
_3._6. _I_n_s_t_a_n_c_e _V_a_r_i_a_b_l_e _N_a_m_e _S_c_o_p_e
In the language described in [.Smalltalk blue.], an
instance variable is known not only to the class protocol in
which it is declared, but is also valid in methods defined
for any subclasses of that class. In the Little Smalltalk
system an instance variable can be referenced only within
the protocol for the class in which it is declared.
_3._7. _I_n_d_e_x_e_d _I_n_s_t_a_n_c_e _V_a_r_i_a_b_l_e_s
Implicitly defined indexed instance variables are not
supported. In any class for which these are desired they
can be easily simulated by including an additional instance
variable, containing an Array, and including the following
methods:
September 19, 1986
- 6 -
Class Whatever
| indexVars |
[
new: size
indexVars <- Array new: size
| at: location
|^ indexVars at: location
| at: location put: value
indexVars at: location put: value
...
The message new: can be used with any class, with an
effect similar to new. That is, if a new instance of the
class is created by sending the message new: to the class
variable, the message is immediately passed on to the new
instance, and the result returned is used as the result of
the creation message.
_3._8. _N_o _P_o_o_l _V_a_r_i_a_b_l_e_s
The concepts of pool variables, global variables, or
class variables are not supported. In their place there is
a new pseudo-variable, ssssmmmmaaaallllllllttttaaaallllkkkk, which responds to the mes-
sages aaaatttt:::: and aaaatttt::::ppppuuuutttt::::. The keys for this collection can be
arbitrary. Although this facility is available, its use is
often a sign of poor program design, and should be avoided.
_3._9. _N_o _A_s_s_o_c_i_a_t_i_o_n_s
The class Dictionary stores keys and values separately,
rather than as instances of Association. The class Associa-
tion, and all messages referring to Associations have been
removed.
_3._1_0. _G_e_n_e_r_a_t_o_r_s _i_n _p_l_a_c_e _o_f _S_t_r_e_a_m_s
The notion of stream has been replaced by the slightly
different notion of _g_e_n_e_r_a_t_o_r_s, in particular the use of the
messages _f_i_r_s_t and _n_e_x_t in subclasses of CCCCoooolllllllleeeeccccttttiiiioooonnnn. Exter-
nal files are supported by an explicit class FFFFiiiilllleeee.
_3._1_1. _P_r_i_m_i_t_i_v_e_s _D_i_f_f_e_r_e_n_t
Both the syntax and the use of primitives has been
changed. Primitives provide an interface between the
Smalltalk world and the underlying system, permitting the
execution of operations that cannot be specified in
Smalltalk. In Little Smalltalk, primitives cannot fail and
September 19, 1986
- 7 -
must return a value (although they may, in error situations,
print an error message and return nnnniiiillll). The syntax for
primitives has been altered to permit the specification of
primitives with an arbitrary number of arguments. The for-
mat for a primitive call is as follows:
<primitive nnnnuuuummmmbbbbeeeerrrr _a_r_g_u_m_e_n_t_l_i_s_t >
Where nnnnuuuummmmbbbbeeeerrrr is the number of the primitive to be executed
(which must be a value between 1 and 255), and _a_r_g_u_m_e_n_t_l_i_s_t
is a list of Smalltalk primary expressions (see Appendix 2).
Appendix 4 lists the meanings of each of the currently
recognized primitive numbers.
_3._1_2. _B_y_t_e _A_r_r_a_y_s
A new syntax has been created for defining an array
composed entirely of unsigned integers in the range 0-255.
These arrays are given a very tight encoding. The syntax is
a pound sign, followed by a left square brace, followed by a
sequence of numbers in the range 0 to 255, followed by a
right square brace.
#[ _n_u_m_b_e_r_s ]
Byte Arrays are used extensively internally.
_3._1_3. _N_e_w _P_s_e_u_d_o _V_a_r_i_a_b_l_e_s
In addition to the pseudo variable ssssmmmmaaaallllllllttttaaaallllkkkk already
mentioned, another pseudo variable, sssseeeellllffffPPPPrrrroooocccceeeessssssss, has beed
added to the Little Smalltalk system. sssseeeellllffffPPPPrrrroooocccceeeessssssss returns
the currently executing process, which can then be passed as
an argument to a semaphore, or be used as a receiver for a
message valid for class PPPPrrrroooocccceeeessssssss. Like sssseeeellllffff and ssssuuuuppppeeeerrrr,
sssseeeellllffffPPPPrrrroooocccceeeessssssss cannot be used at the command level.
_3._1_4. _N_o _D_e_p_e_n_d_e_n_c_y
The notion of dependency, and automatic dependency
updating, is not included in Little Smalltalk.
September 19, 1986
_A_p_p_e_n_d_i_x _1
_C_l_a_s_s _D_e_s_c_r_i_p_t_i_o_n_s
The messages accepted by the classes included in the
Little Smalltalk standard library are described in the fol-
lowing pages. A list of the classes defined, where indenta-
tion is used to imply subclassing, is given below:
Object
UndefinedObject
Symbol
Boolean
True
False
Magnitude
Char
Number
Integer
Float
Radian
Point
Random
Collection
Bag
Set
KeyedCollection
Dictionary
Smalltalk
File
SequenceableCollection
Interval
LinkedList
Semaphore
File
ArrayedCollection
Array
ByteArray
String
Block
Class
Process
In the descriptions of each message the following notes
may occur:
_d Indicates the effect of the message differs slightly
from that given in [.Smalltalk blue.].
_n Indicates the message is not included as part of the
language defined in [.Smalltalk blue.].
_r Indicates the protocol for the message overrides a pro-
tocol given in some superclass. Only where the logical
September 19, 1986
effect of this overriding is important is the message
given a second time; some messages, such as copy, are
overridden in many classes but are not described in the
documentation because the logical effect remains the
same.
September 19, 1986
_A_p_p_e_n_d_i_x _2
_M_a_n _P_a_g_e
A Unix man page for the st command is given on the fol-
lowing page.
September 19, 1986
_A_p_p_e_n_d_i_x _3
_S_y_n_t_a_x _C_h_a_r_t_s
Syntax charts for the language accepted by the Little
Smalltalk system are described on the following pages. The
following is an example class description:
Class Set :Collection
| dict |
[
new
dict <- Dictionary new
| add: newElement
dict at: newElement
ifAbsent: [dict at: newElement put: 1]
| remove: oldElement ifAbsent: exceptionBlock
dict removeKey: oldElement ifAbsent: exceptionBlock
| size
|^ dict size
| occurrencesOf: anElement
|^ dict at: anElement ifAbsent: [0]
| first
dict first.
|^ dict currentKey
| next
dict next.
|^ dict currentKey
]
September 19, 1986
_A_p_p_e_n_d_i_x _4
_P_r_i_m_i_t_i_v_e _N_u_m_b_e_r_s
The following chart gives the function performed by
each primitive in the Little Smalltalk system.
_I_n_f_o_r_m_a_t_i_o_n _a_b_o_u_t _o_b_j_e_c_t_s
0 (not used )
1 class of an object
2 superobject of an object
3 test if class responds to new
4 size of object
5 hash value
6 test if two built-in objects are of the same type
7 object equality testing ( == )
8 various switch toggles
9 numerical generality testing
_I_n_t_e_g_e_r _m_a_n_i_p_u_l_a_t_i_o_n
10 integer addition (both args must be integer)
11 integer subtraction
12 integer < test
13 integer > test
14 integer <_ test
15 integer >_ test
16 integer = test
17 integer ~= test
18 integer multiplication
19 integer //
_B_i_t _m_a_n_i_p_u_l_a_t_i_o_n _a_n_d _o_t_h_e_r _i_n_t_e_g_e_r _v_a_l_u_e_d _f_u_n_c_t_i_o_n_s
20 gcd:
September 19, 1986
21 bitAt:
22 bitOr:
23 bitAnd:
24 bitXor:
25 bitShift:
26 radix:
27 not used
28 integer quo:
29 integer rem:
_O_t_h_e_r _i_n_t_e_g_e_r _f_u_n_c_t_i_o_n_s
30 doPrimitive:withArguments:
31 not used
32 convert random integer to random float
33 bitInvert
34 highBit
35 randomNumber (argument is seed )
36 asCharacter
37 asString
38 factorial
39 asFloat
_C_h_a_r_a_c_t_e_r _m_a_n_i_p_u_l_a_t_i_o_n
40 not used
41. not used
42 character < test
43 character > test
44 character <_ test
45 character >_ test
September 19, 1986
46 character = test
47 character ~= test
48 not used
49 not used
_C_h_a_r_a_c_t_e_r _u_n_a_r_y _f_u_n_c_t_i_o_n_s
50 digitValue
51 isVowel
52 isLetter
53 isLowerCase
54 isUpperCase
55 isSeparator
56 isAlphaNumeric
57 caseShift
58 asString
59 asciiValue
_F_l_o_a_t_i_n_g _p_o_i_n_t _m_a_n_i_p_u_l_a_t_i_o_n
60 floating point addition (both args must be float)
61 floating point subtraction
62 floating point < test
63 floating point > test
64 floating point <_ test
65 floating point >_ test
66 floating point = test
67 floating point ~= test
68 floating point multiplication
69 floating point division
September 19, 1986
_O_t_h_e_r _f_l_o_a_t_i_n_g _p_o_i_n_t _o_p_e_r_a_t_i_o_n_s
70 ln
71 sqrt
72 floor
73 ceiling
74 not used
75 integerPart
76 fractionalPart
77 gamma
78 asString
79 exp
_O_t_h_e_r _n_u_m_e_r_i_c_a_l _f_u_n_c_t_i_o_n_s
80 normalize number to be within 0 and 2J.
81 sin
82 cos
83 not used
84 arcSin
85 arcCos
86 arcTan
87 not used
88 raisedTo:
89 radix:
_S_y_m_b_o_l _C_o_m_m_a_n_d_s
90. not used
91 symbol comparison, returns true or false.
92 printString
93 asString
September 19, 1986
94 print (used internally)
95 not used
96 not used
97 build a new class, arguments are class name, superclass
name, instance variables, messages, methods, context
size.
98 insert an object into class dictionary, first argument
is symbol, second argument is class definition
99 find an object in class dictionary. argument is sym-
bol.
_S_t_r_i_n_g _o_p_e_r_a_t_i_o_n_s
100 string length
101 string compare, case important - return -1, 0 or 1.
102 string compare, case not important
103 string catenation
104 string at:
105 string at:put:
106 copyFrom:length:
107 copy (new string with same chars)
108 asSymbol
109 string printString
_A_r_r_a_y _m_a_n_i_p_u_l_a_t_i_o_n
110 build an untyped object of given size, argument is
integer size.
111 index variable get (first argument is object, second is
index)
112 index variable put (first argument is object, second is
index, third argument is expression)
113 object grow (returns a new object with same instance
variable values as first argument, but with second
argument tacked on end as new instance variable)
114 build an instance of AAAArrrrrrrraaaayyyy of the given size.
September 19, 1986
115 new string of given size
116 ByteArray new:
117 ByteArray size
118 ByteArray at:
119 ByteArray at:put:
_O_u_t_p_u_t _a_n_d _e_r_r_o_r _m_e_s_s_a_g_e_s
120 print string with no return
121 print string with return
122 general error - first argument is receiver, second is
error string
123 print string on error output (with return)
124 not used
125 unix system call
126 print a string at a specific point on the terminal
127 block return without surrounding context
128 reference count less than zero, first argument is
guilty object
129 does not respond error, first argument is receiver,
second is message.
_F_i_l_e _o_p_e_r_a_t_i_o_n_s
130 file open, first argument is name, second argument is
mode
131 file read
132 file write
133 set file mode, first argument is file, second is mode
indicator (anInteger)
134 compute file size in bytes
135 file set location (at:) second argument is location
(anInteger)
136 return current file offset in bytes
September 19, 1986
137 not used
138 not used
139 not used
_P_r_o_c_e_s_s _m_a_n_a_g_e_m_e_n_t
140 block execute (trapped by interpreter)
141 new process (withArguments:)
142 terminate a process
143 perform:withArguments: (trapped by interpreter)
144. not used
145 set state
146 return state
148 start atomic action
149 end atomic action
_O_p_e_r_a_t_i_o_n_s _o_n _c_l_a_s_s_e_s
150 class edit
151 superclass of a class
152 class name (a Symbol)
153 new instance of a class
154 list all commands class responds to
155 respondsTo: , second argument is a symbol
156 class view (drop into editor, but no include)
157 class list
158 variables (returns an array of symbols)
159 not used
_D_a_t_e _a_n_d _T_i_m_e
160 current date and time as string
161 seconds time counter
September 19, 1986
162 clear the screen
_P_l_o_t(_3) _i_n_t_e_r_f_a_c_e
170 clear the screen
171 move the cursor (move(x,y))
172 draw a line (cont(x,y))
173 draw a point (point(x,y))
174 draw a circle (circle(x,y,r))
175 draw an arc (arc(x,y,x0,y0,x1,y1))
176 establish the coordinate space (space(a,b,c,d))
177 draw a line (line(a,b,c,d))
178 print a label (label(s))
179 establish a line type (linemod(s))
September 19, 1986